package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/images")
public class ImagesController {
    @Autowired
    private IUserService userService;

    @PostMapping
    public Map upload(MultipartFile upload) {
        Map<String, Object> map = new HashMap<>();
        try {
            map.put("url", UploadUtil.uploadQiniu(upload));
            //成功上传到服务器状态设为1
            map.put("uploaded", 1);
        } catch (Exception e) {
            //失败则设为0
            map.put("uploaded", 0);
            Map<String, Object> msssage = new HashMap<>();
            msssage.put("msssage", e.getMessage());
            map.put("error", msssage);
            e.printStackTrace();
        }
        return map;
    }


}
